package cn.edu.dutir.corpus.trec;

import cn.edu.dutir.corpus.QueryFiled;
import cn.edu.dutir.corpus.TopicHandler;
import cn.edu.dutir.indri.query.IndriQuery;
import cn.edu.dutir.indri.query.Object2IndriQuery;

public class Trec2IndriQuery extends Object2IndriQuery<TrecTopic> {

	private final QueryFiled mQueryField;

	public Trec2IndriQuery(QueryFiled queryFiled,
			TopicHandler<IndriQuery> indriHandler) {
		super(indriHandler);
		mQueryField = queryFiled;
	}

	public Trec2IndriQuery(TopicHandler<IndriQuery> indriHandler) {
		this(QueryFiled.TITLE, indriHandler);
	}

	@Override
	public IndriQuery indriQuery(TrecTopic topic) {
		int number = Integer.valueOf(topic.number()).intValue();
		String text = null;
		switch (mQueryField) {
		case TITLE:
		case DESC:
		case NARR:
		case TITLE_DESC:
		case TITLE_DESC_NARR:
		case DSEC_NARRA:
			text = topic.queryText();
			break;
		default:
			String msg = "Unsupported query field found";
			throw new IllegalArgumentException(msg);
		}
		return new IndriQuery(number, text);
	}
}
